function hfile = fif_LoadChannelData(hfile, ctype, cspec)
% FIF::LoadChannelData  - retrieve channel data from FIF file
%
% FORMAT:       fif.LoadChannelData(ctype [, cspec]);
%
% Input fields:
%
%       ctype       Channel type, one of
%                   'MEG', 'RMEG', 'EEG', 'MCG', 'STIM',
%                   'EOG', 'EMG', 'ECG', 'MISC', 'RESP', 'ANY'
%       cspec       Channel specification, if ommited: all channels
%
% No output fields.

% Version:  v0.7b
% Build:    7083009
% Date:     Aug-30 2007, 9:23 AM CEST
% Author:   Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin < 2 || ...
    numel(hfile) ~= 1 || ...
   ~isBVQXfile(hfile, 'fif') || ...
   ~ischar(ctype) || ...
   ~any(strcmpi(ctype(:)', ...
     {'any', 'ecg', 'eeg', 'emg', 'eog', ...
      'mcg', 'meg', 'misc', 'resp', 'rmeg', 'stim'}))
    error( ...
        'BVQXfile:BadArgument', ...
        'Invalid call to %s.', ...
        mfilename ...
    );
end

% shortcut to structure
bc = bvqxfile_getcont(hfile.L);
fst = bc.FIFStructure;

% second argument valid?
if nargin > 1
    % ...
else
    
    % find and read channel info elements
    cspec = find(fst.Lookup == 203);
    
    % read those
    fif_ReadElements(hfile, cspec);
end
